package xyz.xuminghai.javafx_learn.demo.login_demo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.time.LocalTime;
import java.util.Objects;

/**
 * 2023/11/7 1:56 星期二<br/>
 * 炫酷的登录页面
 *
 * @author xuMingHai
 */
public class Main extends Application {

    private static final String STYLE_PATH = Objects.requireNonNull(Main.class.getResource("style.css"),
            "style.css 没有找到").toExternalForm();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(new LoginView());
        scene.getStylesheets().add(STYLE_PATH);
        // Control + Enter 重新加载
        scene.getAccelerators().put(new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN),
                () -> {
                    System.out.println("重新加载时间：" + LocalTime.now());
                    scene.getStylesheets().clear();
                    scene.getStylesheets().add(STYLE_PATH);
                    scene.setRoot(new LoginView());
                });
        primaryStage.setScene(scene);
        primaryStage.setMaximized(true);
        primaryStage.initStyle(StageStyle.UNDECORATED);
        primaryStage.show();
    }
}
